package com.oracle.controller;

import com.oracle.compents.ApiResponse;
import com.oracle.compents.PageResult;
import com.oracle.pojo.PhOrder;
import com.oracle.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;



/**
 * controller
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/order")
public class OrderController {

	@Autowired
	private OrderService orderService;

	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findAll")
	public List<PhOrder> findAll(){
		return orderService.findAll();
	}


	/**
	 * 返回全部列表
	 * @return
	 */
	@RequestMapping("/findPage")
	public PageResult  findPage(int page,int rows){
		return orderService.findPage(page, rows);
	}

	/**
	 * 增加
	 * @param order
	 * @return
	 */
	@RequestMapping("/add")
	public ApiResponse add(@RequestBody PhOrder order){
		try {
			orderService.add(order);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}

	/**
	 * 修改
	 * @param order
	 * @return
	 */
	@RequestMapping("/update")
	public ApiResponse update(@RequestBody PhOrder order){
		try {
			orderService.update(order);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}

	/**
	 * 获取实体
	 * @param id
	 * @return
	 */
	@RequestMapping("/findOne")
	public PhOrder findOne(Long id){
		return orderService.findOne(id);
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("/delete")
	public ApiResponse delete(Long [] ids){
		try {
			orderService.delete(ids);
			return ApiResponse.success(null);
		} catch (Exception e) {
			e.printStackTrace();
			return ApiResponse.failed(null);
		}
	}

		/**
	 * 查询+分页
	 * @param brand
	 * @param page
	 * @param rows
	 * @return
	 */
	@RequestMapping("/search")
	public PageResult search(@RequestBody PhOrder order, int page, int rows  ){
		return orderService.findPage(order, page, rows);
	}

}
